import 'package:cat_eye/bean/home_body_bean.dart';
import 'package:cat_eye/root_page/home_page/video_details_widget.dart';
import 'package:cat_eye/util/util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

/*
* @Package: root_page.home_page
* @ClassName: home_banner_page
* @Author: szj
* @CreateDate: 7/28/21 5:18 PM
*
* 首页顶部Banner
*/
// ignore: must_be_immutable
class HomeBannerPageWidget extends StatelessWidget {
  List<ItemList> bannerList = [];

  HomeBannerPageWidget({Key key, @required this.bannerList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(10),
      child: Container(
        height: 180,
        child: Swiper(
          //图片总个数
          itemCount: bannerList.length,
          //自动播放
          autoplay: true,
          //Banner样式
          itemBuilder: (BuildContext context, int index) {
            //点击Banner 添加Hero动画
            return Container(
              // decoration:装饰,设置子控件的背景颜色、形状等
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(12),
                image: DecorationImage(
                  // 网络获取图片 只有这样才能设置圆角

                  image: cachedNetworkImageProvider(
                      bannerList[index].data.cover.feed),
                  // 图片显示样式,类似Android缩放设置
                  fit: BoxFit.cover,
                ),
              ),

              //这样不能设置圆角
              // child: cacheImage(bannerList[index].data.cover.feed,fit: BoxFit.cover),
            );
          },

          /**
           * 添加轮播图指示器
           * DotSwiperPaginationBuilder() 左上角显示圆点
           * FractionPaginationBuilder() 左上角显示数字
           * SwiperPagination()           居中小圆点
           *
           */
          pagination: SwiperPagination(
            alignment: Alignment.bottomRight,
            //设置指示器样式
            builder: DotSwiperPaginationBuilder(
                size: 8,
                activeSize: 8,
                activeColor: Colors.white,
                color: Colors.white24),
          ),
          onTap: (index) {
            Navigator.push(
                context,
                router(
                    widget: VideoDetailsWidget(data: bannerList[index].data)));

            // Navigator.push(context, MaterialPageRoute(builder: (context) {
            //   return VideoDetailsWidget(data: bannerList[index].data);
            // }));
          },
        ),
      ),
    );
  }
}
